/**
 * iview-admin中meta除了原生参数外可配置的参数:
 * meta: {
 *  title: { String|Number|Function }
 *         显示在侧边栏、面包屑和标签栏的文字
 *         使用'{{ 多语言字段 }}'形式结合多语言使用，例子看多语言的路由配置;
 *         可以传入一个回调函数，参数是当前路由对象，例子看动态路由和带参路由
 *  hideInBread: (false) 设为true后此级路由将不会出现在面包屑中，示例看QQ群路由配置
 *  hideInMenu: (false) 设为true后在左侧菜单不会显示该页面选项
 *  notCache: (false) 设为true后页面在切换标签后不会缓存，如果需要缓存，无需设置这个字段，而且需要设置页面组件name属性和路由配置的name一致
 *  access: (null) 可访问该页面的权限数组，当前路由设置的权限会影响子路由
 *  icon: (-) 该页面在左侧菜单、面包屑和标签导航处显示的图标，如果是自定义图标，需要在图标名称前加下划线'_'
 *  beforeCloseName: (-) 设置该字段，则在关闭当前tab页时会去'@/router/before-close.js'里寻找该字段名对应的方法，作为关闭前的钩子函数
 * }
 */
let lifeData = {}

lifeData = localStorage.getItem('lifeData') ? JSON.parse(localStorage.getItem('lifeData')) : { vuex_user: { token: '' } }

// 获取地址栏参数
export const getUrlKey = (name) =>{
  return (decodeURIComponent((new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(location.href) || [, ""])[1].replace(/\+/g, "%20")) || null );
}
const homePath = () => {
  console.log(localStorage.getItem('systemCode'));
  return localStorage.getItem('systemCode') == 'business' ?  () => import('@/view/business/single-page/home/home.vue') :  () => import('@/view/single-page/home/home.vue') 
  
}  
// 业务一级路由
export const firstRouter = [
  {
    path: '/view',
    name: '一级菜单',
    resourceType: 1,
    meta: {
      title: '一级菜单',
      first: true
    },
    component: () => import('@/components/main'),
    children: [{
      path:'baseManage',
      name:'基本信息',
      resourceType:1,
      meta:{
        title:'基础信息'
      },
      component:() => import('@/view/menu/statisticalAnalysis/warehouseStatistics/index.vue'),
      children:[]
    },
    {
      path:'reportingManagement/recipeDetails',
      name:'食谱详情',
      resourceType:1,
      meta:{
        title:'食谱查看 / 详情'
      },
      component:() => import('@/view/menu/reportingManagement/recipeViewing/components/recipeDetails.vue'),
      children:[]
    },
    {
      path:'/view/supplierChangeAnalysis/voucherQuery/voucherQueryJFZItem',
      name:'经费账凭证',
      resourceType:1,
      meta:{
        title:'经费账凭证查看 / 详情'
      },
      component:() => import('@/view/business/businessAccountingParent/voucherQuery/voucherQueryJFZItem'),
      children:[]
    }, 
    {
      path:'/view/supplierChangeAnalysis/voucherQuery/voucherQueryLMZItem',
      name:'粮秣账凭证',
      resourceType:1,
      meta:{
        title:'粮秣账凭证查看 / 详情'
      },
      component:() => import('@/view/business/businessAccountingParent/voucherQuery/voucherQueryLMZItem'),
      children:[]
    }, 
    {
      path:'/view/supplierChangeAnalysis/accountBookMaintenance/grainAndFodderSubjectItem',
      name:'经费摘要',
      resourceType:1,
      meta:{
        title:'添加摘要'
      },
      component:() => import('@/view/business/businessAccountingParent/accountBookMaintenance/grainAndFodderSubjectItem'),
      children:[]
    },
    {
      path:'/view/supplierChangeAnalysis/accountBookQuery/accountBookQueryJFZItemm',
      name:'经费账查询',
      resourceType:1,
      meta:{
        title:'经费账账簿查询 / 查看详情'
      },
      component:() => import('@/view/business/businessAccountingParent/accountBookQuery/accountBookQueryJFZItem'),
      children:[]
    },
    {
      path:'/view/supplierChangeAnalysis/accountBookQuery/accountBookQueryLMZItem',
      name:'粮秣账查询',
      resourceType:1,
      meta:{
        title:'粮秣账账簿查询 / 查看详情'
      },
      component:() => import('@/view/business/businessAccountingParent/accountBookQuery/accountBookQueryLMZItem'),
      children:[]
    },
   {   
        path: 'view/statisticalAnalysis/foodQuantification/foodDetaile',
       component:() => import('@/view/menu/statisticalAnalysis/foodQuantification/components/foodDetaile.vue'),
       name: "食物定量分析图",
       superiorPath: 'foodQuantification',
       resourceType:1,
       meta:{
        title:'业务分析 / 食物定量分析 / 食物定量分析图'
      },
       children: []
  }, {   
        path: '/view/statisticalAnalysis/priceIndex/priceDetaile',
       component:() => import('@/view/menu/statisticalAnalysis/priceIndex/components/priceDetaile'),
       name: "价格指数波动汇总图",
       meta: {
        title: "业务分析 / 价格指数波动汇总 / 价格指数波动汇总图",
       },
       superiorPath: 'priceIndex',
       children: []
  }, {   
        path: '/view/statisticalAnalysis/keyIngredients/keyIngredientsDetaile',
       component:() => import('@/view/menu/statisticalAnalysis/keyIngredients/components/keyIngredientsDetaile.vue'),
       name: "重点食材价格指数波动分析图",
       meta: {
        title: "业务分析 / 价格指数波动汇总 / 价格指数波动汇总图",
       },
       superiorPath: 'keyIngredients',
       children: []
  }, {   
        path: 'view/statisticalAnalysis/mealExpenses/mealDetaile',
       component:() => import('@/view/menu/statisticalAnalysis/mealExpenses/components/mealDetaile.vue'),
       name: "伙食费开支分析图",
       meta: {
        title: "业务分析 / 伙食费开支分析 / 伙食费开支分析图",
       },
       superiorPath: 'mealExpenses',
       children: []
  }
  ]
  }
]
// 基础路由
export let defRouters = [
  {
    path: '/',
    redirect: lifeData.vuex_user && lifeData.vuex_user.token ? '/home' : 'login',
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登录',
      hideInMenu: true
    },
    component: () => import('@/view/login/login.vue')
  },
  {
    path: '/redirect',
    name: 'redirect',
    meta: {
      title: '登录',
      hideInMenu: true
    },
    component: () => import('@/view/redirect/redirect.vue')
  },
]
// 登录后基础路由
export const baseRouters = [
  {
    path: '/main',
    name: 'home',
    component: () => import('@/components/main'),
    meta: {
      hideInMenu: true,
      notCache: true
    },
    children: [
      {
        path: '/home',
        name: 'home',
        meta: {
          hideInMenu: true,
          title: '首页',
          notCache: true,
          icon: 'md-home'
        },
        component: homePath()
      }
    ]
  },
  {
    path: '/personal',
    name: '个人中心',
    component: () => import('@/components/main'),
    meta: {
      hideInBread: true,
      hideInMenu: true
    },
    children: [
      {
        path: 'index',
        name: '个人中心',
        meta: {
          icon: 'md-notifications',
          title: '个人中心',
          beforeCloseName: 'personal',
        },
        component: () => import('@/view/single-page/personal/index.vue')
      }
    ]
  },
  {
    path: '/purchaseMangement',
    name: '采购单查看',
    component: () => import('@/components/main'),
    meta: {
      hideInBread: true,
      hideInMenu: true
    },
    children: [
      {
        path: 'purchaseMangement',
        name: '采购单查看',
        meta: {
          icon: 'md-notifications',
          title: '采购单查看',
          beforeCloseName: 'personal',
        },
        component: () => import('@/view/business/collectingMaterials/purchasingLnquiry/purchaseMangement/purchaseMangement')
      }
    ]
  },{
    path: '/addPurchase',
    name: '添加采购单',
    component: () => import('@/components/main'),
    meta: {
      hideInBread: true,
      hideInMenu: true
    },
    children: [
      {
        path: 'addPurchase',
        name: '添加采购单',
        meta: {
          icon: 'md-notifications',
          title: '添加采购单',
          beforeCloseName: 'personal',
        },
        component: () => import('@/view/business/collectingMaterials/purchasingLnquiry/purchaseMangement/components/addPurchase')
      }
    ]
  },{
    path: '/supplierPurchase',
    name: '查看供应商采购列表',
    component: () => import('@/components/main'),
    meta: {
      hideInBread: true,
      hideInMenu: true
    },
    children: [
      {
        path: 'supplierPurchase',
        name: '查看供应商采购列表',
        meta: {
          icon: 'md-notifications',
          title: '查看供应商采购列表',
          beforeCloseName: 'personal',
        },
        component: () => import('@/view/business/collectingMaterials/purchaseGeneration/supplierPurchase')
      }
    ]
  },{
    path: '/wrehousingDetails',
    name: '入库验收详情',
    component: () => import('@/components/main'),
    meta: {
      hideInBread: true,
      hideInMenu: true
    },
    children: [
      {
        path: 'wrehousingDetails',
        name: '入库验收详情',
        meta: {
          icon: 'md-notifications',
          title: '入库验收详情',
          beforeCloseName: 'personal',
        },
        component: () => import('@/view/business/kitchenMaterial/warehousingAcceptance/components/wrehousingDetails')
      }
    ]
  },{
    path: '/mterialWarehousing',
    name: '物资入库汇总表',
    component: () => import('@/components/main'),
    meta: {
      hideInBread: true,
      hideInMenu: true
    },
    children: [
      {
        path: 'mterialWarehousing',
        name: '物资入库汇总表',
        meta: {
          icon: 'md-notifications',
          title: '物资入库汇总表',
          beforeCloseName: 'personal',
        },
        component: () => import('@/view/business/kitchenMaterial/warehousingAcceptance/components/mterialWarehousing')
      }
    ]
  },{
    path: '/createRequisition',
    name: '创建物资领用单',
    component: () => import('@/components/main'),
    meta: {
      hideInBread: true,
      hideInMenu: true
    },
    children: [
      {
        path: 'createRequisition',
        name: '创建物资领用单',
        meta: {
          icon: 'md-notifications',
          title: '创建物资领用单',
          beforeCloseName: 'personal',
        },
        component: () => import('@/view/business/kitchenMaterial/materialReceipt/components/createRequisition')
      }
    ]
  },
  {
    path: '/outboundDetails',
    name: '出库验收详情',
    component: () => import('@/components/main'),
    meta: {
      hideInBread: true,
      hideInMenu: true
    },
    children: [
      {
        path: 'outboundDetails',
        name: '出库验收详情',
        meta: {
          icon: 'md-notifications',
          title: '出库验收详情',
          beforeCloseName: 'personal',
        },
        component: () => import('@/view/business/kitchenMaterial/outboundRegistration/components/outboundDetails')
      }
    ]
  }
  ,{
    path: '/materialDeliverySummary',
    name: '物资出库汇总表',
    component: () => import('@/components/main'),
    meta: {
      hideInBread: true,
      hideInMenu: true
    },
    children: [
      {
        path: 'materialDeliverySummary',
        name: '物资出库汇总表',
        meta: {
          icon: 'md-notifications',
          title: '物资出库汇总表',
          beforeCloseName: 'personal',
        },
        component: () => import('@/view/business/kitchenMaterial/outboundRegistration/components/materialDeliverySummary')
      }
    ]
  },

  {
    path: '/createHandmade',
    name: '创建食谱',
    component: () => import('@/components/main'),
    meta: {
      hideInBread: true,
      hideInMenu: true
    },
    children: [
      {
        path: 'createHandmadeTwo',
        name: '手工创建食谱',
        meta: {
          icon: 'md-notifications',
          title: '手工创建食谱',
          beforeCloseName: 'personal'
        },
        component: () => import('@/view/business/createCookbook/createHandmade/createHandmadeTwo.vue')
      },
      {
        path: 'createHandmadeThree',
        name: '创建食谱',
        meta: {
          icon: 'md-notifications',
          title: '创建食谱',
          beforeCloseName: 'personal'
        },
        component: () => import('@/view/business/createCookbook/createHandmade/createHandmadeThree.vue')
      },
      {
        path: 'orderDishesPage',
        name: '点菜',
        meta: {
          icon: 'md-notifications',
          title: '点菜',
          beforeCloseName: 'personal'
        },
        component: () => import('@/view/business/createCookbook/orderDishesList/orderDishesPage.vue')
      }
    ]
  },
  // {
  //   path: '/mealDetaile',
  //   name: '伙食费开支分析图',
  //   component: () => import('@/components/main'),
  //   meta: {
  //     hideInBread: true,
  //     hideInMenu: true
  //   },
  //   children: [
  //     {
  //       path: 'index',
  //       name: '伙食费开支分析图',
  //       meta: {
  //         icon: 'md-notifications',
  //         title: '伙食费开支分析图',
  //         beforeCloseName: 'mealDetaile',
  //       },
  //       component: () => import('@/view/menu/statisticalAnalysis/mealExpenses/components/mealDetaile.vue')
  //     }
  //   ]
  // },
  // {
  //   path: '/foodDetaile',
  //   name: '食物定量分析图',
  //   component: () => import('@/components/main'),
  //   meta: {
  //     hideInBread: true,
  //     hideInMenu: true
  //   },
  //   children: [
  //     {
  //       path: 'index',
  //       name: '食物定量分析图',
  //       meta: {
  //         icon: 'md-notifications',
  //         title: '食物定量分析图',
  //         beforeCloseName: 'foodDetaile',
  //       },
  //       component: () => import('@/view/menu/statisticalAnalysis/foodQuantification/components/foodDetaile.vue')
  //     }
  //   ]
  // },
  // {
  //   path: '/priceDetaile',
  //   name: '价格指数波动汇总图',
  //   component: () => import('@/components/main'),
  //   meta: {
  //     hideInBread: true,
  //     hideInMenu: true
  //   },
  //   children: [
  //     {
  //       path: 'index',
  //       name: '价格指数波动汇总图',
  //       meta: {
  //         icon: 'md-notifications',
  //         title: '价格指数波动汇总图',
  //         beforeCloseName: 'priceDetaile',
  //       },
  //       component: () => import('@/view/menu/statisticalAnalysis/priceIndex/components/priceDetaile.vue')
  //     }
  //   ]
  // },{
  //   path: '/keyIngredientsDetaile',
  //   name: '重点食材价格指数波动分析图',
  //   component: () => import('@/components/main'),
  //   meta: {
  //     hideInBread: true,
  //     hideInMenu: true
  //   },
  //   children: [
  //     {
  //       path: 'index',
  //       name: '重点食材价格指数波动分析图',
  //       meta: {
  //         icon: 'md-notifications',
  //         title: '重点食材价格指数波动分析图',
  //         beforeCloseName: 'keyIngredientsDetaile',
  //       },
  //       component: () => import('@/view/menu/statisticalAnalysis/keyIngredients/components/keyIngredientsDetaile.vue')
  //     }
  //   ]
  // },
]
// 错误路由
export const errRouters = [
  {
    path: '*',
    name: 'error-404',
    meta: {
      hideInMenu: true,
      title: '404-页面不存在'
    },
    component: () => import('@/view/error-page/404.vue')
  }
]

if ((lifeData.vuex_user && lifeData.vuex_user.token) || (getUrlKey('user') && getUrlKey('password') && getUrlKey('tokens'))) {
  defRouters = defRouters.concat(baseRouters).concat(firstRouter)
} else {
  defRouters = defRouters.concat(errRouters).concat(firstRouter)
}
console.log(defRouters)

export default defRouters